"use strict";

var gulp = require("gulp");
var gUtil = require("gulp-util");

gulp.task("webpack", function(next) {
    var webpack = require("webpack");
    var config = require("./webpack.config.js");
    webpack(config, (err, stats) => {
        if (err) throw new gUtil.PluginError("webpack", err);
        next();
    });
});

gulp.task("less", function() {
    var less = require("gulp-less");
    gulp.src("./less/main.less")
        .pipe(less({
            compress: false
        }))
        .on("error", e => {
            console.log(e);
        })
        .pipe(gulp.dest("../www/css/"));
});

gulp.task("watch", function() {
    gulp.watch("./less/*.less", [
        "less"
    ]);
    gulp.watch("./**/*.js", [
        "webpack"
    ]);
});

gulp.task("default", ["webpack", "less"]);
